<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Category extends MX_Controller {


	function __construct(){

		$this->load->model('category/category_model');
	}
	
	function index($category_id){
		/*if(!empty($category_id)){
			$data['match_cat'] = $category_id;
			$this->session->set_userdata('sess_cat', $data['match_cat']);
		}else{
			$data['match_cat'] = $this->session->userdata('sess_cat');
		}*/
		
		
		$data['product'] = $this->category_model->get_list_product(/*$data['match_cat']*/$category_id);
		
		$this->load->view('category/category',$data);
		
		
	}
	
	function grid($category_id){
		if(!empty($category_id)){
			$data['match_cat'] = $category_id;
			$this->session->set_userdata('sess_cat', $data['match_cat']);
		}else{
			$data['match_cat'] = $this->session->userdata('sess_cat');
		}
		
		$offset = $this->uri->segment(4);
		$limit = '12';
		if(!$offset){
			$page = 0;
		}else{
			$page = $offset; 	
		}
		
		$data['product'] = $this->category_model->get_list_product($data['match_cat'], $page, $limit);
		
		$config_pagination['base_url']    = site_url('category/grid/'.$category_id);
		$config_pagination['total_rows']  = count($this->category_model->get_list_product($data['match_cat'], 0, 0));
		$config_pagination['per_page']    = $limit;
		$config_pagination['uri_segment'] = 4;
		$config_pagination['num_links']   = 4;

		//pagination style
		$config_pagination['full_tag_open'] = '<div class="pagination"><ul>';
		$config_pagination['full_tag_close'] = '</ul></div>';

		$config_pagination['first_link'] = 'First';
		$config_pagination['first_tag_open']  = '<li>';
		$config_pagination['first_tag_close'] = '</li>';

		$config_pagination['last_link'] = 'Last';
		$config_pagination['last_tag_open']  = '<li>';
		$config_pagination['last_tag_close'] = '</li>';

		$config_pagination['next_link'] = '&gt;';
		$config_pagination['next_tag_open']  = '<li>';
		$config_pagination['next_tag_close'] = '</li>';

		$config_pagination['prev_link'] = '&lt;';
		$config_pagination['prev_tag_open'] = '<li>';
		$config_pagination['prev_tag_close'] = '</li>';

		$config_pagination['cur_tag_open'] = '<li><span class="current">';
		$config_pagination['cur_tag_close'] = '</span></li>';

		$config_pagination['num_tag_open'] = '<li>';
		$config_pagination['num_tag_close'] = '</li>';

		$this->pagination->initialize($config_pagination); 
		$data['pagination'] = $this->pagination->create_links();
		$this->load->view('category/category_grid',$data);
	}
	
	function tes(){
		$this->load->view('category/product');
	}
	
}

/* End of file common.php */